package com.yanqu.road.server.manger.cricket.skillhandler.attround.handler;

import com.yanqu.road.entity.cricket.helper.AddHpResult;
import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.gameplayer.module.cricket.battle.CricketGame;
import com.yanqu.road.server.gameplayer.module.cricket.model.BattleData;
import com.yanqu.road.server.gameplayer.module.cricket.model.SkillData;
import com.yanqu.road.server.manger.cricket.skillhandler.attround.CricketSkillAttRoundStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CricketSkill407Strategy implements CricketSkillAttRoundStrategy {
    @Override
    public boolean skillHandle(CricketGame cricketGame, SkillData skillData, SkillData baseAttSkill, AddHpResult baseAttReHpResult, BattleData action, BattleData target, CricketProto.CricketAttackRound.Builder attackRoundBuilder, long battleFrameId) {
        //普通攻击触发 miss也一样触发
        if (baseAttSkill.getSkillEffect().getSkillType() == eSkillType.CricketBattleSkill137.getValue()){
            //活着才能触发 不会复活
            if (action.isAlive()){
                CricketProto.CricketBattleFrame.Builder skill407FrameBuilder = cricketGame.newBattleFrameBuilder();
                skill407FrameBuilder.setSkillId(skillData.getSkillId());
                skill407FrameBuilder.setActionUserId(target.getUserId());
                skill407FrameBuilder.setTargetUserId(target.getUserId());
                //增加的生命上限
                long addHp = BigDecimal.valueOf(target.getMaxHp()).multiply(BigDecimal.valueOf(skillData.getSkillEffect().getP1())).divide(BigDecimal.valueOf(1000),2, RoundingMode.DOWN).longValue();
                //剩余的血量增加
                AddHpResult addHpResult = target.addHp(addHp);

                skill407FrameBuilder.setAttack(addHpResult.getValue());
                //双方属性信息
                //注入回合数据数组
                cricketGame.fillRemainHp(skill407FrameBuilder);
                attackRoundBuilder.addAfterRound(skill407FrameBuilder);
            }
        }


        return false;
    }
}
